package com.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.model.auto.CompanyInfo;
import com.example.model.auto.NewsAccount;
import com.example.model.auto.NewsInfo;
import com.example.service.INewsInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 新闻热点信息表 前端控制器
 * </p>
 *
 * @author 达瓦里氏
 * @since 2021-12-03
 */
@RestController
@RequestMapping("/news")
public class NewsInfoController {

    @Autowired
    private INewsInfoService iNewsInfoService;

    /*查询博客*/
    @GetMapping("/getNews")
    public List<NewsInfo> getNews(){
        return iNewsInfoService.list();
    }

    /*通过类型查询博客列表*/
    @PostMapping("/selectNewsByType/{Value}")
    public List<NewsAccount> selectNewsByType(@PathVariable("Value") String Value){
        return iNewsInfoService.selectNewsByType(Value);
    }

    /*通过内容查询博客列表*/
    @PostMapping("/selectNewsByAll/{Value}")
    public List<NewsAccount> selectNewsByAll(@PathVariable("Value") String Value){
        return iNewsInfoService.selectNewsByAll(Value);
    }

    /*通过id查询博客*/
    @GetMapping("/getNewsById/{id}")
    public NewsInfo getNewsById(@PathVariable("id") int id){
        return iNewsInfoService.getById(id);
    }

    /*修改博客*/
    @PostMapping("/updateNews")
    public void updateNews(@RequestBody NewsInfo newsInfo){
        iNewsInfoService.updateById(newsInfo);
    }

    /*添加博客*/
    @PostMapping("/setNews")
    public void setNews(@RequestBody NewsInfo newsInfo){
        newsInfo.setNewsTime(new Date());
        iNewsInfoService.save(newsInfo);
    }

    /*删除博客*/
    @PostMapping("/deletedById/{id}")
    public boolean deleted(@PathVariable("id") int id){
        return iNewsInfoService.removeById(id);
    }

    /*联表查询*/
    @GetMapping("/selectNews")
    public List<NewsAccount> selectNews(){
        return iNewsInfoService.selectNews();
    }

    /*根据id查询资讯*/
    @GetMapping("/selectNewsById/{id}")
    public List<NewsAccount> selectNewsById(@PathVariable("id") int id){
        return iNewsInfoService.selectNewsById(id);
    }



}
